package com.src;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import com.src.R;
import com.views.AboutView;
import com.views.AchievementsView;
import com.views.MapView;
import com.views.StatisticsView;
import com.views.SupportView;

public class LifetimeTracker extends Activity {

	private static final int SHOW_MAP = 1;
	private static final int SHOW_STATS = 2;
	private static final int SHOW_ACHIEVEMENTS = 3;
	private static final int SHOW_INFO = 4;

	//Variables used through whole project
	public static Drawable background = null;
	public static String versionNr = "1.0";
	public static String versionDate = "July 24th 2011";


	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		background = getResources().getDrawable(R.drawable.statachbg);
		setContentView(R.layout.main);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		menu.add(0, SHOW_MAP, 0, R.string.show_map);
		menu.add(0, SHOW_STATS, 0, R.string.show_stats);
		menu.add(0, SHOW_ACHIEVEMENTS, 0, R.string.show_achievements);
		menu.add(0, SHOW_INFO, 0, R.string.show_info);

		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case SHOW_MAP:
			//show the google map
			View mv = new MapView(this);
			setContentView(mv);
			return true;

		case SHOW_STATS:
			//show statistics
			View sv = new StatisticsView(this);
			setContentView(sv);
			return true;

		case SHOW_ACHIEVEMENTS:
			//show achievements
			View av = new AchievementsView(this);
			setContentView(av);
			return true;

		case SHOW_INFO:
			//show info options
			showInfoOptions();
			return true;
		}
		return false;
	}

	@Override
	public void onResume(){
		super.onResume();
		setContentView(R.layout.main);
	}

	public void showInfoOptions() {
		// TODO Auto-generated method stub   
		final CharSequence[] items = {"About", "Contact Support"};
		AlertDialog.Builder listBuilder = new AlertDialog.Builder(LifetimeTracker.this);
		listBuilder.setTitle("Info");
		listBuilder.setItems(items, new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int item) {
				if(!activateView(item)) {
				Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
				}
			}
		});
		AlertDialog alertList = listBuilder.create();
		alertList.show();    
	}
	
	public boolean activateView(int item) {
		switch (item) {
		case 0:
			View av = new AboutView(this);
			setContentView(av);
			return true;
		case 1:
			View sv = new SupportView(this);
			setContentView(sv);
			return true;
		}
		return false;
	}
}